<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>JSON Metadata</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
function togglePopup(material_id) {
  var popup = document.getElementById(material_id);
  popup.classList.toggle("show");
}
</script>

<link href="../docs-assets/Popups.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html"><img src="../docs-assets/Inform.png" height=72> </a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=0> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="https://github.com/ganelson/inweb"><img src="../docs-assets/github.png" height=0> inweb</a></li>
<li><a href="https://github.com/ganelson/intest"><img src="../docs-assets/github.png" height=0> intest</a></li>
</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'JSON Metadata' generated by inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../inbuildn.html">Inbuild Modules</a></li><li><a href="index.html">supervisor</a></li><li><a href="index.html#2">Chapter 2: Conceptual Framework</a></li><li><b>JSON Metadata</b></li></ul></div>
<p class="purpose">Managing JSON-encoded metadata files for resources such as kits.</p>

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. </b>Every <a href="2-cps.html#SP1" class="internal">inbuild_copy</a> can optionally contain a pointer to a JSON value called
<span class="extract"><span class="extract-syntax">metadata_record</span></span>. The code in this section reads a file of JSON metadata into
that record, validating it (a) as syntactically correct JSON, (b) as JSON which
matches the Inbuild schema for what copy metadata should look like, and (c) as
identifying the copy which it purports to identify.
</p>

<p class="commentary">In practice, (a) and (b) are delegated to the <a href="../foundation/4-jsn.html" class="internal">JSON (in foundation)</a> library.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">JSONMetadata::read_metadata_file</span><button class="popup" onclick="togglePopup('usagePopup1')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup1">Usage of <span class="code-font"><span class="function-syntax">JSONMetadata::read_metadata_file</span></span>:<br/>Extension Services - <a href="5-es.html#SP2_4">&#167;2.4</a><br/>Kit Services - <a href="5-ks.html#SP5">&#167;5</a><br/>Language Services - <a href="5-ls.html#SP2">&#167;2</a><br/>Project Services - <a href="5-ps2.html#SP2">&#167;2</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inbuild_copy</span><span class="plain-syntax"> *</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><span class="identifier-syntax">filename</span><span class="plain-syntax"> *</span><span class="identifier-syntax">F</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">repairing_title</span><span class="plain-syntax">, </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">repairing_author</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">JSON_requirement</span><span class="plain-syntax"> *</span><span class="identifier-syntax">req</span><span class="plain-syntax"> = </span><a href="2-jm.html#SP3" class="function-link"><span class="function-syntax">JSONMetadata::requirements</span></a><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">contents</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">TextFiles::read</span><span class="plain-syntax">(</span><span class="identifier-syntax">F</span><span class="plain-syntax">, </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">, </span><span class="string-syntax">"unable to read file of JSON metadata"</span><span class="plain-syntax">, </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        &amp;</span><a href="2-jm.html#SP1" class="function-link"><span class="function-syntax">JSONMetadata::read_metadata_file_helper</span></a><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, </span><span class="identifier-syntax">contents</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">SVEXPLAIN</span><span class="plain-syntax">(2, </span><span class="string-syntax">"(read JSON metadata file found at %f)\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">F</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">text_file_position</span><span class="plain-syntax"> </span><span class="identifier-syntax">tfp</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TextFiles::at</span><span class="plain-syntax">(</span><span class="identifier-syntax">F</span><span class="plain-syntax">, </span><span class="constant-syntax">1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">JSON_value</span><span class="plain-syntax"> *</span><span class="identifier-syntax">obj</span><span class="plain-syntax"> = </span><span class="identifier-syntax">JSON::decode</span><span class="plain-syntax">(</span><span class="identifier-syntax">contents</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">tfp</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">obj</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">obj</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">JSON_type</span><span class="plain-syntax"> == </span><span class="identifier-syntax">ERROR_JSONTYPE</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="2-jm.html#SP1_1" class="named-paragraph-link"><span class="named-paragraph">Report a syntax error in JSON</span><span class="named-paragraph-number">1.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">req</span><span class="plain-syntax">) </span><span class="named-paragraph-container code-font"><a href="2-jm.html#SP1_2" class="named-paragraph-link"><span class="named-paragraph">Validate the JSON read in</span><span class="named-paragraph-number">1.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">contents</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">metadata_record</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="2-jm.html#SP1_3" class="named-paragraph-link"><span class="named-paragraph">Examine the "is" member of the metadata object</span><span class="named-paragraph-number">1.3</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="2-jm.html#SP1_4" class="named-paragraph-link"><span class="named-paragraph">Police the "needs"</span><span class="named-paragraph-number">1.4</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">JSON_value</span><span class="plain-syntax"> *</span><span class="identifier-syntax">compatibility</span><span class="plain-syntax"> = </span><span class="identifier-syntax">JSON::look_up_object</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"compatibility"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">compatibility</span><span class="plain-syntax">) </span><span class="named-paragraph-container code-font"><a href="2-jm.html#SP1_5" class="named-paragraph-link"><span class="named-paragraph">Extract compatibility</span><span class="named-paragraph-number">1.5</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">JSON_value</span><span class="plain-syntax"> *</span><span class="identifier-syntax">rights</span><span class="plain-syntax"> = </span><span class="identifier-syntax">JSON::look_up_object</span><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">metadata_record</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"rights"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">rights</span><span class="plain-syntax">) </span><a href="2-lcn.html#SP3" class="function-link"><span class="function-syntax">Licences::from_JSON</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">licence</span><span class="plain-syntax">, </span><span class="identifier-syntax">rights</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">JSONMetadata::read_metadata_file_helper</span><button class="popup" onclick="togglePopup('usagePopup2')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup2">Usage of <span class="code-font"><span class="function-syntax">JSONMetadata::read_metadata_file_helper</span></span>:<br/>Registries - <a href="2-rgs.html#SP3">&#167;3</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">text</span><span class="plain-syntax">, </span><span class="identifier-syntax">text_file_position</span><span class="plain-syntax"> *</span><span class="identifier-syntax">tfp</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">void</span><span class="plain-syntax"> *</span><span class="identifier-syntax">v_state</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">contents</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *) </span><span class="identifier-syntax">v_state</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">contents</span><span class="plain-syntax">, </span><span class="string-syntax">"%S\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">text</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP1_1" class="paragraph-anchor"></a><b>&#167;1.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Report a syntax error in JSON</span><span class="named-paragraph-number">1.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">, </span><span class="string-syntax">"the metadata contains a syntax error: '%S'"</span><span class="plain-syntax">, </span><span class="identifier-syntax">obj</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">if_error</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-cps.html#SP5" class="function-link"><span class="function-syntax">Copies::attach_error</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><a href="2-ce.html#SP2" class="function-link"><span class="function-syntax">CopyErrors::new_T</span></a><span class="plain-syntax">(</span><span class="constant-syntax">METADATA_MALFORMED_CE</span><span class="plain-syntax">, -1, </span><span class="identifier-syntax">err</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">)</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-jm.html#SP1">&#167;1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP1_2" class="paragraph-anchor"></a><b>&#167;1.2. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Validate the JSON read in</span><span class="named-paragraph-number">1.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">linked_list</span><span class="plain-syntax"> *</span><span class="identifier-syntax">validation_errors</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NEW_LINKED_LIST</span><span class="plain-syntax">(</span><span class="identifier-syntax">text_stream</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">JSON::validate</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj</span><span class="plain-syntax">, </span><span class="identifier-syntax">req</span><span class="plain-syntax">, </span><span class="identifier-syntax">validation_errors</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">err</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOOP_OVER_LINKED_LIST</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">, </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax">, </span><span class="identifier-syntax">validation_errors</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">msg</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">msg</span><span class="plain-syntax">, </span><span class="string-syntax">"the metadata did not validate: '%S'"</span><span class="plain-syntax">, </span><span class="identifier-syntax">err</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="2-cps.html#SP5" class="function-link"><span class="function-syntax">Copies::attach_error</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><a href="2-ce.html#SP2" class="function-link"><span class="function-syntax">CopyErrors::new_T</span></a><span class="plain-syntax">(</span><span class="constant-syntax">METADATA_MALFORMED_CE</span><span class="plain-syntax">, -1, </span><span class="identifier-syntax">msg</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">msg</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-jm.html#SP1">&#167;1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP1_3" class="paragraph-anchor"></a><b>&#167;1.3. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Examine the "is" member of the metadata object</span><span class="named-paragraph-number">1.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">JSON_value</span><span class="plain-syntax"> *</span><span class="identifier-syntax">is</span><span class="plain-syntax"> = </span><span class="identifier-syntax">JSON::look_up_object</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"is"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">JSON_value</span><span class="plain-syntax"> *</span><span class="identifier-syntax">type</span><span class="plain-syntax"> = </span><span class="identifier-syntax">JSON::look_up_object</span><span class="plain-syntax">(</span><span class="identifier-syntax">is</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"type"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">type</span><span class="plain-syntax">) </span><span class="named-paragraph-container code-font"><a href="2-jm.html#SP1_3_1" class="named-paragraph-link"><span class="named-paragraph">Make sure the type is correct</span><span class="named-paragraph-number">1.3.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">JSON_value</span><span class="plain-syntax"> *</span><span class="identifier-syntax">title</span><span class="plain-syntax"> = </span><span class="identifier-syntax">JSON::look_up_object</span><span class="plain-syntax">(</span><span class="identifier-syntax">is</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"title"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">title</span><span class="plain-syntax">) </span><span class="named-paragraph-container code-font"><a href="2-jm.html#SP1_3_2" class="named-paragraph-link"><span class="named-paragraph">Make sure the title is correct</span><span class="named-paragraph-number">1.3.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">JSON_value</span><span class="plain-syntax"> *</span><span class="identifier-syntax">author</span><span class="plain-syntax"> = </span><span class="identifier-syntax">JSON::look_up_object</span><span class="plain-syntax">(</span><span class="identifier-syntax">is</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"author"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">author</span><span class="plain-syntax">) </span><span class="named-paragraph-container code-font"><a href="2-jm.html#SP1_3_3" class="named-paragraph-link"><span class="named-paragraph">Make sure the author is correct</span><span class="named-paragraph-number">1.3.3</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">JSON_value</span><span class="plain-syntax"> *</span><span class="identifier-syntax">version</span><span class="plain-syntax"> = </span><span class="identifier-syntax">JSON::look_up_object</span><span class="plain-syntax">(</span><span class="identifier-syntax">is</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"version"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">version</span><span class="plain-syntax">) </span><span class="named-paragraph-container code-font"><a href="2-jm.html#SP1_3_4" class="named-paragraph-link"><span class="named-paragraph">Read the version number and apply it</span><span class="named-paragraph-number">1.3.4</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">JSON_value</span><span class="plain-syntax"> *</span><span class="identifier-syntax">version_range</span><span class="plain-syntax"> = </span><span class="identifier-syntax">JSON::look_up_object</span><span class="plain-syntax">(</span><span class="identifier-syntax">is</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"version-range"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">version_range</span><span class="plain-syntax">) </span><span class="named-paragraph-container code-font"><a href="2-jm.html#SP1_3_5" class="named-paragraph-link"><span class="named-paragraph">Forbid the use of a version range</span><span class="named-paragraph-number">1.3.5</span></a></span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-jm.html#SP1">&#167;1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP1_3_1" class="paragraph-anchor"></a><b>&#167;1.3.1. </b>So, for example, if this file is from what we think is a kit, then it needs
to say that <span class="extract"><span class="extract-syntax">is.type</span></span> is <span class="extract"><span class="extract-syntax">"kit"</span></span>.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Make sure the type is correct</span><span class="named-paragraph-number">1.3.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">type_text</span><span class="plain-syntax"> = </span><span class="identifier-syntax">type</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">if_string</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">required_text</span><span class="plain-syntax"> = </span><span class="identifier-syntax">I</span><span class="string-syntax">"&lt;unknown"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">edition</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">work</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">genre</span><span class="plain-syntax"> == </span><span class="identifier-syntax">kit_genre</span><span class="plain-syntax">) </span><span class="identifier-syntax">required_text</span><span class="plain-syntax"> = </span><span class="identifier-syntax">I</span><span class="string-syntax">"kit"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">edition</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">work</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">genre</span><span class="plain-syntax"> == </span><span class="identifier-syntax">extension_genre</span><span class="plain-syntax">) </span><span class="identifier-syntax">required_text</span><span class="plain-syntax"> = </span><span class="identifier-syntax">I</span><span class="string-syntax">"extension"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">edition</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">work</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">genre</span><span class="plain-syntax"> == </span><span class="identifier-syntax">extension_bundle_genre</span><span class="plain-syntax">) </span><span class="identifier-syntax">required_text</span><span class="plain-syntax"> = </span><span class="identifier-syntax">I</span><span class="string-syntax">"extension"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">edition</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">work</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">genre</span><span class="plain-syntax"> == </span><span class="identifier-syntax">language_genre</span><span class="plain-syntax">) </span><span class="identifier-syntax">required_text</span><span class="plain-syntax"> = </span><span class="identifier-syntax">I</span><span class="string-syntax">"language"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">edition</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">work</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">genre</span><span class="plain-syntax"> == </span><span class="identifier-syntax">project_file_genre</span><span class="plain-syntax">) </span><span class="identifier-syntax">required_text</span><span class="plain-syntax"> = </span><span class="identifier-syntax">I</span><span class="string-syntax">"project"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">edition</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">work</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">genre</span><span class="plain-syntax"> == </span><span class="identifier-syntax">project_bundle_genre</span><span class="plain-syntax">) </span><span class="identifier-syntax">required_text</span><span class="plain-syntax"> = </span><span class="identifier-syntax">I</span><span class="string-syntax">"project"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Str::ne</span><span class="plain-syntax">(</span><span class="identifier-syntax">type_text</span><span class="plain-syntax">, </span><span class="identifier-syntax">required_text</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">msg</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">msg</span><span class="plain-syntax">, </span><span class="string-syntax">"the metadata misidentifies the type as '%S', but it should be '%S'"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">type_text</span><span class="plain-syntax">, </span><span class="identifier-syntax">required_text</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="2-cps.html#SP5" class="function-link"><span class="function-syntax">Copies::attach_error</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><a href="2-ce.html#SP2" class="function-link"><span class="function-syntax">CopyErrors::new_T</span></a><span class="plain-syntax">(</span><span class="constant-syntax">METADATA_MALFORMED_CE</span><span class="plain-syntax">, -1, </span><span class="identifier-syntax">msg</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">msg</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">JSON_value</span><span class="plain-syntax"> *</span><span class="identifier-syntax">kit_details</span><span class="plain-syntax"> = </span><span class="identifier-syntax">JSON::look_up_object</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"kit-details"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">kit_details</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">Str::ne</span><span class="plain-syntax">(</span><span class="identifier-syntax">type_text</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"kit"</span><span class="plain-syntax">))) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">, </span><span class="string-syntax">"the metadata contains kit-details but is not for a kit"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="2-cps.html#SP5" class="function-link"><span class="function-syntax">Copies::attach_error</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><a href="2-ce.html#SP2" class="function-link"><span class="function-syntax">CopyErrors::new_T</span></a><span class="plain-syntax">(</span><span class="constant-syntax">METADATA_MALFORMED_CE</span><span class="plain-syntax">, -1, </span><span class="identifier-syntax">err</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">JSON_value</span><span class="plain-syntax"> *</span><span class="identifier-syntax">extension_details</span><span class="plain-syntax"> = </span><span class="identifier-syntax">JSON::look_up_object</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"extension-details"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">extension_details</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">Str::ne</span><span class="plain-syntax">(</span><span class="identifier-syntax">type_text</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"extension"</span><span class="plain-syntax">))) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">, </span><span class="string-syntax">"the metadata contains extension-details but is not for an extension"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="2-cps.html#SP5" class="function-link"><span class="function-syntax">Copies::attach_error</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><a href="2-ce.html#SP2" class="function-link"><span class="function-syntax">CopyErrors::new_T</span></a><span class="plain-syntax">(</span><span class="constant-syntax">METADATA_MALFORMED_CE</span><span class="plain-syntax">, -1, </span><span class="identifier-syntax">err</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">JSON_value</span><span class="plain-syntax"> *</span><span class="identifier-syntax">language_details</span><span class="plain-syntax"> = </span><span class="identifier-syntax">JSON::look_up_object</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"language-details"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">language_details</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">Str::ne</span><span class="plain-syntax">(</span><span class="identifier-syntax">type_text</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"language"</span><span class="plain-syntax">))) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">, </span><span class="string-syntax">"the metadata contains language-details but is not for a language"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="2-cps.html#SP5" class="function-link"><span class="function-syntax">Copies::attach_error</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><a href="2-ce.html#SP2" class="function-link"><span class="function-syntax">CopyErrors::new_T</span></a><span class="plain-syntax">(</span><span class="constant-syntax">METADATA_MALFORMED_CE</span><span class="plain-syntax">, -1, </span><span class="identifier-syntax">err</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">JSON_value</span><span class="plain-syntax"> *</span><span class="identifier-syntax">project_details</span><span class="plain-syntax"> = </span><span class="identifier-syntax">JSON::look_up_object</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"project-details"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">project_details</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">Str::ne</span><span class="plain-syntax">(</span><span class="identifier-syntax">type_text</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"project"</span><span class="plain-syntax">))) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">, </span><span class="string-syntax">"the metadata contains project-details but is not for a project"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="2-cps.html#SP5" class="function-link"><span class="function-syntax">Copies::attach_error</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><a href="2-ce.html#SP2" class="function-link"><span class="function-syntax">CopyErrors::new_T</span></a><span class="plain-syntax">(</span><span class="constant-syntax">METADATA_MALFORMED_CE</span><span class="plain-syntax">, -1, </span><span class="identifier-syntax">err</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-jm.html#SP1_3">&#167;1.3</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP1_3_2" class="paragraph-anchor"></a><b>&#167;1.3.2. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Make sure the title is correct</span><span class="named-paragraph-number">1.3.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">repairing_title</span><span class="plain-syntax">, </span><span class="string-syntax">"%S"</span><span class="plain-syntax">, </span><span class="identifier-syntax">title</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">if_string</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Str::ne</span><span class="plain-syntax">(</span><span class="identifier-syntax">title</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">if_string</span><span class="plain-syntax">, </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">edition</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">work</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">title</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">repairing_title</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            ;</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Str::len</span><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">edition</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">work</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">title</span><span class="plain-syntax">) &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">, </span><span class="string-syntax">"the metadata says the title is '%S' when it should be '%S'"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">title</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">if_string</span><span class="plain-syntax">, </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">edition</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">work</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">title</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">else</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">, </span><span class="string-syntax">"the metadata says the title is '%S' but it is untitled"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">title</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">if_string</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="2-cps.html#SP5" class="function-link"><span class="function-syntax">Copies::attach_error</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><a href="2-ce.html#SP2" class="function-link"><span class="function-syntax">CopyErrors::new_T</span></a><span class="plain-syntax">(</span><span class="constant-syntax">METADATA_MALFORMED_CE</span><span class="plain-syntax">, -1, </span><span class="identifier-syntax">err</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-jm.html#SP1_3">&#167;1.3</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP1_3_3" class="paragraph-anchor"></a><b>&#167;1.3.3. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Make sure the author is correct</span><span class="named-paragraph-number">1.3.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">repairing_author</span><span class="plain-syntax">, </span><span class="string-syntax">"%S"</span><span class="plain-syntax">, </span><span class="identifier-syntax">author</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">if_string</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Str::ne</span><span class="plain-syntax">(</span><span class="identifier-syntax">author</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">if_string</span><span class="plain-syntax">, </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">edition</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">work</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">author_name</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">repairing_author</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            ;</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Str::len</span><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">edition</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">work</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">author_name</span><span class="plain-syntax">) &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">, </span><span class="string-syntax">"the metadata says the author is '%S' when it should be '%S'"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">author</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">if_string</span><span class="plain-syntax">, </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">edition</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">work</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">author_name</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">else</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">, </span><span class="string-syntax">"the metadata says the author is '%S', but it has no author"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">author</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">if_string</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="2-cps.html#SP5" class="function-link"><span class="function-syntax">Copies::attach_error</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><a href="2-ce.html#SP2" class="function-link"><span class="function-syntax">CopyErrors::new_T</span></a><span class="plain-syntax">(</span><span class="constant-syntax">METADATA_MALFORMED_CE</span><span class="plain-syntax">, -1, </span><span class="identifier-syntax">err</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-jm.html#SP1_3">&#167;1.3</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP1_3_4" class="paragraph-anchor"></a><b>&#167;1.3.4. </b>Unlike those tests, here we simply trust the metadata to be correctly supplying
a version number.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Read the version number and apply it</span><span class="named-paragraph-number">1.3.4</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">semantic_version_number</span><span class="plain-syntax"> </span><span class="identifier-syntax">V</span><span class="plain-syntax"> = </span><span class="identifier-syntax">VersionNumbers::from_text</span><span class="plain-syntax">(</span><span class="identifier-syntax">version</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">if_string</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">VersionNumbers::is_null</span><span class="plain-syntax">(</span><span class="identifier-syntax">V</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">, </span><span class="string-syntax">"cannot read version number '%S'"</span><span class="plain-syntax">, </span><span class="identifier-syntax">version</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">if_string</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="2-cps.html#SP5" class="function-link"><span class="function-syntax">Copies::attach_error</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><a href="2-ce.html#SP2" class="function-link"><span class="function-syntax">CopyErrors::new_T</span></a><span class="plain-syntax">(</span><span class="constant-syntax">METADATA_MALFORMED_CE</span><span class="plain-syntax">, -1, </span><span class="identifier-syntax">err</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">edition</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">version</span><span class="plain-syntax"> = </span><span class="identifier-syntax">VersionNumbers::from_text</span><span class="plain-syntax">(</span><span class="identifier-syntax">version</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">if_string</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-jm.html#SP1_3">&#167;1.3</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP1_3_5" class="paragraph-anchor"></a><b>&#167;1.3.5. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Forbid the use of a version range</span><span class="named-paragraph-number">1.3.5</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">, </span><span class="string-syntax">"the metadata should specify an exact version, not a range"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-cps.html#SP5" class="function-link"><span class="function-syntax">Copies::attach_error</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><a href="2-ce.html#SP2" class="function-link"><span class="function-syntax">CopyErrors::new_T</span></a><span class="plain-syntax">(</span><span class="constant-syntax">METADATA_MALFORMED_CE</span><span class="plain-syntax">, -1, </span><span class="identifier-syntax">err</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">)</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-jm.html#SP1_3">&#167;1.3</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP1_4" class="paragraph-anchor"></a><b>&#167;1.4. </b>It would have been possible to write the schema in a way which would exclude
the possibilities blocked here, but only by making it cumbersome. Besides,
checking here results in more explicit error messages.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Police the "needs"</span><span class="named-paragraph-number">1.4</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">JSON_value</span><span class="plain-syntax"> *</span><span class="identifier-syntax">needs</span><span class="plain-syntax"> = </span><span class="identifier-syntax">JSON::look_up_object</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"needs"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">needs</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">JSON_value</span><span class="plain-syntax"> *</span><span class="identifier-syntax">E</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOOP_OVER_LINKED_LIST</span><span class="plain-syntax">(</span><span class="identifier-syntax">E</span><span class="plain-syntax">, </span><span class="identifier-syntax">JSON_value</span><span class="plain-syntax">, </span><span class="identifier-syntax">needs</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">if_list</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">JSON_value</span><span class="plain-syntax"> *</span><span class="identifier-syntax">if_clause</span><span class="plain-syntax"> = </span><span class="identifier-syntax">JSON::look_up_object</span><span class="plain-syntax">(</span><span class="identifier-syntax">E</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"if"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">JSON_value</span><span class="plain-syntax"> *</span><span class="identifier-syntax">unless_clause</span><span class="plain-syntax"> = </span><span class="identifier-syntax">JSON::look_up_object</span><span class="plain-syntax">(</span><span class="identifier-syntax">E</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"unless"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">JSON_value</span><span class="plain-syntax"> *</span><span class="identifier-syntax">needs_clause</span><span class="plain-syntax"> = </span><span class="identifier-syntax">JSON::look_up_object</span><span class="plain-syntax">(</span><span class="identifier-syntax">E</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"needs"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">if_clause</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">unless_clause</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">, </span><span class="string-syntax">"cannot give both 'if' and 'unless' in same requirement"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><a href="2-cps.html#SP5" class="function-link"><span class="function-syntax">Copies::attach_error</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><a href="2-ce.html#SP2" class="function-link"><span class="function-syntax">CopyErrors::new_T</span></a><span class="plain-syntax">(</span><span class="constant-syntax">METADATA_MALFORMED_CE</span><span class="plain-syntax">, -1, </span><span class="identifier-syntax">err</span><span class="plain-syntax">));</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><a href="2-jm.html#SP2" class="function-link"><span class="function-syntax">JSONMetadata::not_both</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><span class="identifier-syntax">if_clause</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"'if' clause of a requirement"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="2-jm.html#SP2" class="function-link"><span class="function-syntax">JSONMetadata::not_both</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><span class="identifier-syntax">unless_clause</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"'unless' clause of a requirement"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="2-jm.html#SP2" class="function-link"><span class="function-syntax">JSONMetadata::not_both</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><span class="identifier-syntax">needs_clause</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"'needs' clause of a requirement"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-jm.html#SP1">&#167;1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. </b>All very pedantic, but:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">JSONMetadata::not_both</span><button class="popup" onclick="togglePopup('usagePopup3')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup3">Usage of <span class="code-font"><span class="function-syntax">JSONMetadata::not_both</span></span>:<br/><a href="2-jm.html#SP1_4">&#167;1.4</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inbuild_copy</span><span class="plain-syntax"> *</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><span class="identifier-syntax">JSON_value</span><span class="plain-syntax"> *</span><span class="identifier-syntax">clause</span><span class="plain-syntax">, </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">where</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">clause</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">JSON_value</span><span class="plain-syntax"> *</span><span class="identifier-syntax">version</span><span class="plain-syntax"> = </span><span class="identifier-syntax">JSON::look_up_object</span><span class="plain-syntax">(</span><span class="identifier-syntax">clause</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"version"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">JSON_value</span><span class="plain-syntax"> *</span><span class="identifier-syntax">version_range</span><span class="plain-syntax"> = </span><span class="identifier-syntax">JSON::look_up_object</span><span class="plain-syntax">(</span><span class="identifier-syntax">clause</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"version-range"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">version</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">version_range</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">, </span><span class="string-syntax">"%S specifies both a version and a version-range"</span><span class="plain-syntax">, </span><span class="identifier-syntax">where</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="2-cps.html#SP5" class="function-link"><span class="function-syntax">Copies::attach_error</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><a href="2-ce.html#SP2" class="function-link"><span class="function-syntax">CopyErrors::new_T</span></a><span class="plain-syntax">(</span><span class="constant-syntax">METADATA_MALFORMED_CE</span><span class="plain-syntax">, -1, </span><span class="identifier-syntax">err</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">version</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">semantic_version_number</span><span class="plain-syntax"> </span><span class="identifier-syntax">V</span><span class="plain-syntax"> = </span><span class="identifier-syntax">VersionNumbers::from_text</span><span class="plain-syntax">(</span><span class="identifier-syntax">version</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">if_string</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">VersionNumbers::is_null</span><span class="plain-syntax">(</span><span class="identifier-syntax">V</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">, </span><span class="string-syntax">"cannot read version '%S' in %S"</span><span class="plain-syntax">, </span><span class="identifier-syntax">version</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">if_string</span><span class="plain-syntax">, </span><span class="identifier-syntax">where</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><a href="2-cps.html#SP5" class="function-link"><span class="function-syntax">Copies::attach_error</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><a href="2-ce.html#SP2" class="function-link"><span class="function-syntax">CopyErrors::new_T</span></a><span class="plain-syntax">(</span><span class="constant-syntax">METADATA_MALFORMED_CE</span><span class="plain-syntax">, -1, </span><span class="identifier-syntax">err</span><span class="plain-syntax">));</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">version_range</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">, </span><span class="string-syntax">"'version-range' is not yet supported in %S"</span><span class="plain-syntax">, </span><span class="identifier-syntax">where</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="2-cps.html#SP5" class="function-link"><span class="function-syntax">Copies::attach_error</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><a href="2-ce.html#SP2" class="function-link"><span class="function-syntax">CopyErrors::new_T</span></a><span class="plain-syntax">(</span><span class="constant-syntax">METADATA_MALFORMED_CE</span><span class="plain-syntax">, -1, </span><span class="identifier-syntax">err</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP1_5" class="paragraph-anchor"></a><b>&#167;1.5. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Extract compatibility</span><span class="named-paragraph-number">1.5</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">compatibility_specification</span><span class="plain-syntax"> *</span><span class="identifier-syntax">CS</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Compatibility::from_text</span><span class="plain-syntax">(</span><span class="identifier-syntax">compatibility</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">if_string</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">CS</span><span class="plain-syntax">) </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">edition</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">compatibility</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CS</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">, </span><span class="string-syntax">"cannot read compatibility '%S'"</span><span class="plain-syntax">, </span><span class="identifier-syntax">compatibility</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">if_string</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="2-cps.html#SP5" class="function-link"><span class="function-syntax">Copies::attach_error</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><a href="2-ce.html#SP2" class="function-link"><span class="function-syntax">CopyErrors::new_T</span></a><span class="plain-syntax">(</span><span class="constant-syntax">METADATA_MALFORMED_CE</span><span class="plain-syntax">, -1, </span><span class="identifier-syntax">err</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-jm.html#SP1">&#167;1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. </b>The following returns the schema needed for (b); we will load it in from a file
in the Inform/Inbuild installation, but will then cache the result so that it
loads only once.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">dictionary</span><span class="plain-syntax"> *</span><span class="identifier-syntax">JSON_resource_metadata_requirements</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>

<span class="identifier-syntax">JSON_requirement</span><span class="plain-syntax"> *</span><span class="function-syntax">JSONMetadata::requirements</span><button class="popup" onclick="togglePopup('usagePopup4')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup4">Usage of <span class="code-font"><span class="function-syntax">JSONMetadata::requirements</span></span>:<br/><a href="2-jm.html#SP1">&#167;1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">JSON_resource_metadata_requirements</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">filename</span><span class="plain-syntax"> *</span><span class="identifier-syntax">F</span><span class="plain-syntax"> = </span><span class="identifier-syntax">InstalledFiles::filename</span><span class="plain-syntax">(</span><span class="identifier-syntax">RESOURCE_JSON_REQS_IRES</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">TextFiles::exists</span><span class="plain-syntax">(</span><span class="identifier-syntax">F</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">JSON_resource_metadata_requirements</span><span class="plain-syntax"> = </span><span class="identifier-syntax">JSON::read_requirements_file</span><span class="plain-syntax">(</span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, </span><span class="identifier-syntax">F</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">JSON_requirement</span><span class="plain-syntax"> *</span><span class="identifier-syntax">req</span><span class="plain-syntax"> =</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">JSON::look_up_requirements</span><span class="plain-syntax">(</span><span class="identifier-syntax">JSON_resource_metadata_requirements</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"resource-metadata"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">req</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"JSON metadata file did not define &lt;resource-metadata&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">req</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="2-rgs.html">&#10094;</a></li><li class="progresschapter"><a href="P-wtmd.html">P</a></li><li class="progresschapter"><a href="1-sm.html">1</a></li><li class="progresscurrentchapter">2</li><li class="progresssection"><a href="2-gnr.html">gnr</a></li><li class="progresssection"><a href="2-wrk.html">wrk</a></li><li class="progresssection"><a href="2-edt.html">edt</a></li><li class="progresssection"><a href="2-cps.html">cps</a></li><li class="progresssection"><a href="2-ce.html">ce</a></li><li class="progresssection"><a href="2-rqr.html">rqr</a></li><li class="progresssection"><a href="2-nst.html">nst</a></li><li class="progresssection"><a href="2-rgs.html">rgs</a></li><li class="progresscurrent">jm</li><li class="progresssection"><a href="2-lcn.html">lcn</a></li><li class="progresschapter"><a href="3-bg.html">3</a></li><li class="progresschapter"><a href="4-em.html">4</a></li><li class="progresschapter"><a href="5-es.html">5</a></li><li class="progresschapter"><a href="6-st.html">6</a></li><li class="progresschapter"><a href="7-tm.html">7</a></li><li class="progressnext"><a href="2-lcn.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

